{include file="Public:header2"/}
<body style="min-height: 100%;background-color: #fff">
<div style="padding: 0 20px;position: relative;z-index: 99;border-bottom: 1px solid #e5e5e5;line-height: 39px;height: 39px;overflow: hidden;">
      <span style="visibility: visible;">
        <a href="{:url('/admin/qy_level_jiang_list',['qy_level_id'=>$qy_level_id])}" style="padding-right: 8px;line-height: 22px;font-size: 14px;color: #333!important;">奖品管理<span class="layui-box">&gt;</span></a>
        <a href="javascript:;"> <cite>添加奖品</cite></a>
      </span>
</div>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <form onsubmit="return false;">
                        <div class="layui-form" wid100 lay-filter="">
                            <div class="layui-form-item">
                                <label class="layui-form-label">类型</label>
                                <div class="layui-input-inline" style="width: 700px">
                                    <input type="radio" name="type" value="1" lay-filter="type" class="layui-input" title="普通奖励(优惠券)" checked>
                                    <input type="radio" name="type" value="2" lay-filter="type" class="layui-input" title="高级奖励(奖品)" >
                                </div>
                            </div>
                            <div class="layui-form-item coupon_id">
                                <label class="layui-form-label">优惠券</label>
                                <div class="layui-input-inline" style="width: 600px">
                                    <select name="coupon_id">
                                        <option  value="">--请选择--</option>
                                        {foreach name="coupon" item="vo"}
                                        <option value="{$vo.id}">{$vo.title}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item z_num">
                                <label class="layui-form-label">优惠券赠送数量</label>
                                <div class="layui-input-inline">
                                    <input type="number" name="z_num" placeholder="请输入优惠券赠送数量" autocomplete="off" class="layui-input"  style="width: 600px">
                                </div>
                            </div>
                            <div class="layui-form-item title">
                                <label class="layui-form-label">名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="title" value="" lay-verify="required" placeholder="请输入名称" autocomplete="off" class="layui-input" style="width: 600px">
                                </div>
                            </div>
                            <div class="layui-form-item shang_id">
                                <label class="layui-form-label">奖品类型</label>
                                <div class="layui-input-inline" style="width: 600px">
                                    <select name="shang_id">
                                        <option  value="">--请选择--</option>
                                        {foreach name="shang" item="vo"}
                                        <option value="{$vo.id}">{$vo.title}</option>
                                        {/foreach}
                                    </select>
                                </div>
                            </div>
                            <div class="layui-form-item jiang_price" style="display: none">
                                <label class="layui-form-label">奖品价值</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="jiang_price" placeholder="请输入奖品价值" autocomplete="off" class="layui-input"  style="width: 600px">
                                </div>
                            </div>
                            <div class="layui-form-item jiang_probability" style="display: none">
                                <label class="layui-form-label">奖品概率</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="probability" placeholder="请输入奖品概率" autocomplete="off" class="layui-input"  style="width: 600px">
                                </div>
                            </div>
                            <div class="layui-form-item money" style="display: none">
                                <label class="layui-form-label">奖品兑换价</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="money" placeholder="请输入奖品兑换价" autocomplete="off" class="layui-input"  style="width: 600px">
                                </div>
                            </div>
                            <div class="layui-form-item sc_money" style="display: none">
                                <label class="layui-form-label">奖品参考价</label>
                                <div class="layui-input-inline">
                                    <input type="text" name="sc_money" placeholder="请输入奖品参考价" autocomplete="off" class="layui-input"  style="width: 600px">
                                </div>
                            </div>
                            <div class="layui-form-item imgurl" style="display: none">
                                <label class="layui-form-label">盒子封面图</label>
                                <div class="layui-input-inline">
                                    <input type="hidden" name="imgurl" value="" lay-verify="required" placeholder="请上传图片" autocomplete="off" class="layui-input" >
                                    <img style="float:left;width:120px;" class="" id="imgurl" src="/static/image/upload.jpg">
                                </div>
                            </div>
                            <input type="hidden" name="qy_level_id" value="{$qy_level_id}">
                            <div class="layui-form-item">
                                <div class="layui-input-block">
                                    <button class="layui-btn" onclick="return check()">确认保存</button>
                                </div>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="Public:footer"/}
</body>
</html>
<script type="text/javascript">
    layui.use(['layer','form','upload','laydate'], function(){
        var $ = layui.$;
        var form = layui.form;
        var upload = layui.upload;
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#arrive_time' //指定元素
            ,type : 'date'
            ,trigger : 'click'
        });

        $(".title").hide();
        $(".jiang_price").hide();
        $(".money").hide();
        $(".sc_money").hide();
        $(".imgurl").hide();
        $(".shang_id").hide();
        $(".jiang_probability").hide();

        form.on('radio(type)', function (data) {
            var value = data.value;   //  当前选中的value值
            if(value == 1){
                $(".coupon_id").show();
                $(".z_num").show();

                $(".title").hide();
                $(".jiang_price").hide();
                $(".money").hide();
                $(".sc_money").hide();
                $(".imgurl").hide();
                $(".shang_id").hide();
                $(".jiang_probability").hide();
            }else {
                $(".coupon_id").hide();
                $(".z_num").hide();

                $(".title").show();
                $(".jiang_price").show();
                $(".money").show();
                $(".sc_money").show();
                $(".imgurl").show();
                $(".shang_id").show();
                $(".jiang_probability").show();
            }
        });

        //执行实例
        var uploadInst = upload.render({
            accept:'imgurl'
            ,elem: '#imgurl' //绑定元素
            ,url: '/admin/picture' //上传接口
            ,done: function(res){
                //上传完毕回调
                if(res.status == 1){ //成功
                    layer.msg("上传成功",{icon:1,time:1000},function(){
                        $("#imgurl").attr("src",res.data.path);  //单图
                        $("input[name=imgurl]").val(res.data.imgurl);
                    });
                }else{ //失败
                    layer.msg(res.msg,{icon:2,anim:6,time:1500});
                }
            }
            ,error: function(){
                //请求异常回调
                layer.msg('服务繁忙，请稍后再试',{icon:2,anim:6,time:1500});
            }
        });

         //选择是否发货
        form.on('radio(is_yu)', function(data){
          // console.log(data.elem); //得到 radio 原始 DOM 对象
          // console.log(data.value); //被点击的 radio 的 value 值
          if(data.value == 1 ){
            $('.arrive_time').hide();
          }else{
            $('.arrive_time').show();
          }
        });
        
    });

    function check(){
        var url="{:url('/admin/qy_level_jiang_add')}";
        var $ = layui.$;
        var load=layer.load(2);
        $.post(url,$("form").serialize(),function(data){
            if(data.status==1){
                layer.msg(data.msg,{icon:1,time:1000},function(){
                    location.href="{:url('/admin/qy_level_jiang_list',['qy_level_id'=>$qy_level_id])}";
                });
            }else{
                layer.msg(data.msg,{icon:2,anim:6,time:1500},function(){
                    layer.close(load);
                });
            }
        })
    }
</script>
